<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>

<script>
// Test rgba() color parsing results.

var ctx = document.createElement('canvas').getContext('2d');

function parseRGBAString(rgbaString, expectedColor) {
    ctx.globalCompositeOperation = 'copy';
    ctx.fillStyle = '#666';
    ctx.fillStyle = rgbaString;
    ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
    var data = ctx.getImageData(0, 0, 1, 1).data;
    assert_array_equals(expectedColor, data);
}

var testScenarios = [
	['Test Case 1', 'rgba(0.9.9%, 0%, 0%, 1)', [102, 102, 102, 255]],
	['Test Case 2', 'rgba(0, 0.., 0, 1)', [102, 102, 102, 255]],
	['Test Case 3', 'rgba(10%, .%, 0%, 1)', [102, 102, 102, 255]],
	['Test Case 4', 'rgba(13.37%1337%, 5%, 50.0%, 1)', [102, 102, 102, 255]],
	['Test Case 5', 'rgba(%, 50%, 50.0%, 1)', [102, 102, 102, 255]],
	['Test Case 6', 'rgba(50.0%, 50%, a%, 1)', [102, 102, 102, 255]],
	['Test Case 7', 'rgba(500%, 0%, 0%, 1)', [255, 0, 0, 255]],
	['Test Case 8', 'rgba(100%, 100%, 100%, 1)', [255, 255, 255, 255]],
	['Test Case 9', 'rgba(10.5%, 80%, 70%, 1)', [27, 204, 179, 255]],
	['Test Case 10', 'rgba(0%, 0%, 0%, 1)', [0, 0, 0, 255]],
	['Test Case 11', 'rgba(50.0%, 50.0%, 50.0%, 1)', [128, 128, 128, 255]],
	['Test Case 12', 'rgba(100%, 100%, 100%, 1)', [255, 255, 255, 255]],
	['Test Case 13', 'rgba(10.5%, 80%, 70%, 1)', [27, 204, 179, 255]],
	['Test Case 14', 'rgba(55.5%, 0.5%, 110%, 1)', [142, 1, 255, 255]],
	['Test Case 15', 'rgba(60.59998%, 0.59999%, 110.12345%, 1)', [155, 2, 255, 255]],
	['Test Case 16', 'rgba(10.999%, 0.999%, 0.000009%, 1)', [28, 3, 0, 255]],
	['Test Case 17', 'rgba(79.99999%, 99.99999%, 500%, 1)', [204, 255, 255, 255]],
	['Test Case 18', 'rgba(0, 0, 0, -0.10)', [0, 0, 0, 0]],
	['Test Case 19', 'rgba(0, 0, 0, -5.0)', [0, 0, 0, 0]],
	['Test Case 20', 'rgba(0, 0, 0, 5.0)', [0, 0, 0, 255]],
	['Test Case 21', 'rgba(0, 0, 0, -1)', [0, 0, 0, 0]],
	['Test Case 22', 'rgba(0, 0, 0, 0)', [0, 0, 0, 0]],
	['Test Case 23', 'rgba(0, 0, 0, 2)', [0, 0, 0, 255]],
	['Test Case 24', 'rgba(0, 0, 0, 2.0)', [0, 0, 0, 255]],
	['Test Case 25', 'rgba(0, 0, 0, 0.0)', [0, 0, 0, 0]],
	['Test Case 26', 'rgba(0, 0, 0, 00.0)', [0, 0, 0, 0]],
	['Test Case 27', 'rgba(0, 0, 0, 0.00)', [0, 0, 0, 0]],
	['Test Case 28', 'rgba(0, 0, 0, .1)', [0, 0, 0, 26]],
	['Test Case 29', 'rgba(0, 0, 0, .2)', [0, 0, 0, 51]],
	['Test Case 30', 'rgba(0, 0, 0, .3)', [0, 0, 0, 77]],
	['Test Case 31', 'rgba(0, 0, 0, .4)', [0, 0, 0, 102]],
	['Test Case 32', 'rgba(0, 0, 0, .5)', [0, 0, 0, 128]],
	['Test Case 33', 'rgba(0, 0, 0, .6)', [0, 0, 0, 153]],
	['Test Case 34', 'rgba(0, 0, 0, .7)', [0, 0, 0, 179]],
	['Test Case 35', 'rgba(0, 0, 0, .8)', [0, 0, 0, 204]],
	['Test Case 36', 'rgba(0, 0, 0, .9)', [0, 0, 0, 230]],
	['Test Case 37', 'rgba(0, 0, 0, 0.1)', [0, 0, 0, 26]],
	['Test Case 38', 'rgba(0, 0, 0, 0.2)', [0, 0, 0, 51]],
	['Test Case 39', 'rgba(0, 0, 0, 0.3)', [0, 0, 0, 77]],
	['Test Case 40', 'rgba(0, 0, 0, 0.4)', [0, 0, 0, 102]],
	['Test Case 41', 'rgba(0, 0, 0, 0.5)', [0, 0, 0, 128]],
	['Test Case 42', 'rgba(0, 0, 0, 0.6)', [0, 0, 0, 153]],
	['Test Case 43', 'rgba(0, 0, 0, 0.7)', [0, 0, 0, 179]],
	['Test Case 44', 'rgba(0, 0, 0, 0.8)', [0, 0, 0, 204]],
	['Test Case 45', 'rgba(0, 0, 0, 0.9)', [0, 0, 0, 230]],
	['Test Case 46', 'rgba(0, 0, 0, 1.0)', [0, 0, 0, 255]],
	['Test Case 47', 'rgba(0, 0, 0, 0.10)', [0, 0, 0, 26]],
	['Test Case 48', 'rgba(0, 0, 0, 0.20)', [0, 0, 0, 51]],
	['Test Case 49', 'rgba(0, 0, 0, 0.30)', [0, 0, 0, 77]],
	['Test Case 50', 'rgba(0, 0, 0, 0.40)', [0, 0, 0, 102]],
	['Test Case 51', 'rgba(0, 0, 0, 0.50)', [0, 0, 0, 128]],
	['Test Case 52', 'rgba(0, 0, 0, 0.60)', [0, 0, 0, 153]],
	['Test Case 53', 'rgba(0, 0, 0, 0.70)', [0, 0, 0, 179]],
	['Test Case 54', 'rgba(0, 0, 0, 0.80)', [0, 0, 0, 204]],
	['Test Case 55', 'rgba(0, 0, 0, 0.90)', [0, 0, 0, 230]],
	['Test Case 56', 'rgba(0, 0, 0, 1.00)', [0, 0, 0, 255]],
	['Test Case 57', 'rgba(0, 0, 0, .10)', [0, 0, 0, 26]],
	['Test Case 58', 'rgba(0, 0, 0, .20)', [0, 0, 0, 51]],
	['Test Case 59', 'rgba(0, 0, 0, .30)', [0, 0, 0, 77]],
	['Test Case 60', 'rgba(0, 0, 0, .40)', [0, 0, 0, 102]],
	['Test Case 61', 'rgba(0, 0, 0, .50)', [0, 0, 0, 128]],
	['Test Case 62', 'rgba(0, 0, 0, .60)', [0, 0, 0, 153]],
	['Test Case 63', 'rgba(0, 0, 0, .70)', [0, 0, 0, 179]],
	['Test Case 64', 'rgba(0, 0, 0, .80)', [0, 0, 0, 204]],
	['Test Case 65', 'rgba(0, 0, 0, .90)', [0, 0, 0, 230]],
	['Test Case 66', 'rgba(0, 0, 0, 0.10000000000000000000000)', [0, 0, 0, 26]],
	['Test Case 67', 'rgba(0, 0, 0, 0.20000000000000000000000)', [0, 0, 0, 51]],
	['Test Case 68', 'rgba(0, 0, 0, 0.30000000000000000000000)', [0, 0, 0, 77]],
	['Test Case 69', 'rgba(0, 0, 0, 0.40000000000000000000000)', [0, 0, 0, 102]],
	['Test Case 70', 'rgba(0, 0, 0, 0.50000000000000000000000)', [0, 0, 0, 128]],
	['Test Case 71', 'rgba(0, 0, 0, 0.60000000000000000000000)', [0, 0, 0, 153]],
	['Test Case 72', 'rgba(0, 0, 0, 0.70000000000000000000000)', [0, 0, 0, 179]],
	['Test Case 73', 'rgba(0, 0, 0, 0.80000000000000000000000)', [0, 0, 0, 204]],
	['Test Case 74', 'rgba(0, 0, 0, 0.90000000000000000000000)', [0, 0, 0, 230]],
	['Test Case 75', 'rgba(0, 0, 0, 1.00000000000000000000000)', [0, 0, 0, 255]],
	['Test Case 76', 'rgba(0, 0, 0, 0.990)', [0, 0, 0, 252]],
	['Test Case 77', 'rgba(0, 0, 0, 0.991)', [0, 0, 0, 253]],
	['Test Case 78', 'rgba(0, 0, 0, 0.992)', [0, 0, 0, 253]],
	['Test Case 79', 'rgba(0, 0, 0, 0.993)', [0, 0, 0, 253]],
	['Test Case 80', 'rgba(0, 0, 0, 0.994)', [0, 0, 0, 253]],
	['Test Case 81', 'rgba(0, 0, 0, 0.995)', [0, 0, 0, 254]],
	['Test Case 82', 'rgba(0, 0, 0, 0.996)', [0, 0, 0, 254]],
	['Test Case 83', 'rgba(0, 0, 0, 0.997)', [0, 0, 0, 254]],
	['Test Case 84', 'rgba(0, 0, 0, 0.998)', [0, 0, 0, 254]],
	['Test Case 85', 'rgba(0, 0, 0, 0.999)', [0, 0, 0, 255]],
];

generate_tests(parseRGBAString, testScenarios);

</script>
</body>
</html>
